﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using com.fmtx.Model;
using com.fmtx.IDal;
using fmtx.Framework.DALFactory;

namespace website.Areas.Action.Controllers
{
    public class PraiseController : BaseController
    {
        //
        // GET: /Action/Praise/
        IPraise praise = DataAccess<IPraise>.GetObject();

        /// <summary>
        /// 赞美文章
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [IsLoginJson]
        public ActionResult DoPariseA(int id)
        {
            IArticle article = DataAccess<IArticle>.GetObject();
            bool istrue = true;
            var msg = "";
            if (!praise.HasPraise(userInfo.Uid, Target.ARTICLE, id))
            {
                Praise model = new Praise();
                model.TagId = id;
                model.TagType = Target.ARTICLE;
                model.Uid = userInfo.Uid;
                praise.Add(model);
                var abean=article.Get(id);
                abean.PraiseCount++;
                article.Update(abean);
                ArticleCache.DoSup(id);
                msg = "赞美成功！";
            }
            else {
                istrue = false;
                msg = "赞过了！";
            }
            return Json(new { success=istrue,msg=msg},JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 赞美文章
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [IsLoginJson]
        public ActionResult DoPariseP(int id)
        {
            IPicture picture = DataAccess<IPicture>.GetObject();
            bool istrue = true;
            var msg = "";
            if (!praise.HasPraise(userInfo.Uid, Target.PICTRUE, id))
            {
                Praise model = new Praise();
                model.TagId = id;
                model.TagType = Target.PICTRUE;
                model.Uid = userInfo.Uid;
                praise.Add(model);
                var pbean = picture.Get(id);
                pbean.PraiseCount++;
                picture.Update(pbean);
                PictureCache.DoSup(id);
                msg = "赞美成功！";
            }
            else
            {
                istrue = false;
                msg = "赞过了！";
            }
            return Json(new { success = istrue, msg = msg }, JsonRequestBehavior.AllowGet);
        }

    }
}
